﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;

namespace MyUtility
{
    public partial class NotePadPage : PhoneApplicationPage
    {
        public NotePadPage()
        {
            InitializeComponent();
        }
		IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
        IsolatedStorageFileStream fileStream;
		private void bnt01_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			fileStream = 
			fileStorage.CreateFile("mytext.txt");
			StreamWriter writer = new StreamWriter(fileStream);
			writer.Write(myText.Text);
			writer.Close();
			
        }

        private void bnt02_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			fileStream = fileStorage.OpenFile("mytext.txt",FileMode.Open,FileAccess.Read);
			StreamReader reader = new StreamReader(fileStream);
			myText.Text = reader.ReadToEnd();
			reader.Close();
        }

        private void bnt04_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			storageSetting.Remove("mytxt.text");
			storageSetting.Add("mytxt.text",myText.Text);
			storageSetting.Save();
        }
		IsolatedStorageSettings storageSetting = IsolatedStorageSettings.ApplicationSettings;
        private void bnt03_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			if(storageSetting.Contains("mytxt.text")){
				myText.Text = (string) storageSetting["mytxt.text"];
			}			
        }
    }
}
